package ltd.sshine.networkserver.port;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.regex.Pattern;

@Component
public class SinglePortHandler implements PortHandler{
    private final Pattern compile = Pattern.compile("^\\d+$");
    @Override
    public boolean check(String port) {
        return compile.matcher(port).find();
    }

    @Override
    public int genPort(String port, List<Integer> ignore) {
        for (Integer s : ignore) {
            if (s.equals(Integer.parseInt(port)))
                return -1;
        }
        return Integer.parseInt(port);
    }
}
